var mysql = require('mysql');
var mysql_config = require("./../../util/mysql_config");
var log = require("./../../util/loginfo").getInstand;

var pool = mysql.createPool({
    connectionLimit: 10000,
    host: mysql_config.host,
    user: mysql_config.user,
    password: mysql_config.password,
    port: mysql_config.port,
    database: 'gameaccount',
    charset: "utf8mb4",
});


exports.get_Mark = function get_Mark(_info, callback_c) {

    var sql = "select * from mark WHERE userId = ? and gameId = ? order by balanceTime desc LIMIT ?, 20";
    var index = (_info.pageNo - 1) * 20;
    var values = [];
    values.push(_info.userId);
    values.push(_info.gameId);
    values.push(index);
    pool.getConnection(function (err, connection) {
        connection.query({sql: sql, values: values}, function (err, rows) {
            connection.release();
            if (err) {
                log.info("get_Mark");
                log.err(err);
                callback_c(0);
            } else {
                if (rows.length) {
                    let strBet = [];
                    for (i in rows) {
                        if (rows[i] != null) {
                            log.info("bet_list ",rows[i].bet_list);
                            let s = {
                                round_no: rows[i].round_no,
                                result:  rows[i].result,
                                bet_list: rows[i].bet_list
                            }
                            strBet.push(JSON.stringify(s)); 
                        }
                    }
                    callback_c(1, strBet);
                } else {
                    log.info("22222222222222");
                    callback_c(2);
                }
            }
        });
        values = [];
    });
};